﻿using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Repositories.Internal;
using Core.Toolkit.Core.Application;
using Core.Toolkit.Core.Entitys;
using Core.Toolkit.Core.Repositories.Internal;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Core.SimpleTemp.Application.YH
{
    public class YH_BaseService<TDto, TEntity, TRepository> : BaseAppService<TDto, TEntity, TRepository, CoreDBContext> where TEntity : Entity, new() where TDto : Core.Toolkit.Core.Application.Dto where TRepository : BaseDBRepository<CoreDBContext, TEntity>
    {
        public YH_BaseService(TRepository repository) : base(repository)
        {
        }

        public virtual LoadPageOffsetModel<TEntity, TDto> GetLoadPageOffsetMode(PagingModel<TDto> pagingModel)
        {
            throw new CustomOperationException("记得重写YH_BaseService的GetLoadPageOffsetMode");
        }

        public async Task DeleteAsync(PagingModel<TDto> pagingModel)
        {
            var loadPageOffsetModel = this.GetLoadPageOffsetMode(pagingModel);
            await base.DeleteAsync(loadPageOffsetModel.QueryWhere);
        }
        public async Task<int> SelectCountAsync(PagingModel<TDto> pagingModel)
        {
            var loadPageOffsetMode = this.GetLoadPageOffsetMode(pagingModel);
            var queryWhere = loadPageOffsetMode.QueryWhere;
            return await _repository.QueryBase().Where(queryWhere).CountAsync();
        }
    }
}
